﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneticAlgorithm.Demo.Common.Function.UnaryFunction
{
    [DisplayText(FunctionType.UnaryFunction3, "y=e^(r*x)*cos(w*x)+j*e^(r*x)*sin(w*x)")]
    internal class UnaryFunction3 : IUnaryFunction
    {
        public UnaryFunction3()
        {
            this.Range = (-5, 10);
            this.Solve = SolveType.Min;
            this.Accuracy = 6;
        }
        public (double lower, double upper) Range { get; set; }
        public byte Accuracy { get; set; }
        public SolveType Solve { get; set; }
        public int GeneMinLength => (int)Math.Ceiling(Math.Log2((Range.upper - Range.lower) * Math.Pow(10, Accuracy)));

        public double Func(double x)
        {
            const double r = -0.5d;// r>0震荡增大，x<0震荡减小
            const double w = 2d;
            const double j = 2;
            // e^(r*x)*cos(w*x)+j*e^(r*x)*sin(w*x)
            return Math.Pow(Math.E, r * x) * Math.Cos(w * x) + j * Math.Pow(Math.E, r * x) * Math.Sin(w * x);
        }
    }
}
